package leetcode.每日一题;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2022/10/15 9:11 PM
 * @description：https://leetcode.cn/problems/car-pooling/
 */
public class 拼车 {
    @Test
    public void test() {

    }

    class Solution {
        public boolean carPooling(int[][] trips, int capacity) {
            int[] hash = new int[1001];
            for (int[] trip : trips) {
                int p = trip[0];
                int from = trip[1];
                int to = trip[2];
                hash[from] += p;
                hash[to] -= p;
            }
            int num = 0;
            for (int h : hash) {
                num += h;
                if (num > capacity) {
                    return false;
                }
            }
            return true;
        }
    }
}
